<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>02-v-bind动态绑定class对象语法.html</title>
</head>

<body>
  <div id='app' v-cloak>
    <h2 class="active">{{message}}</h2>
    <!-- 普通class与绑定clss可以共存 -->
    <h2 class="title" :class="active">{{message}}</h2>

    <!-- 对象boolean key:value -->
    <h2 :class="{active:isActive,line:isLine}">{{message}}</h2>
    <button v-on:click="btnClick">按一下</button>

    <!-- v-bind调用方法需要 () -->
    <h2 class="title" :class="getClasses()">{{message}}</h2>
  </div>
  <script src='../js/vue.js'></script>
  <script>
    const app = new Vue({
      el: '#app',
      data: {
        message: 'hello Vue',
        active: 'active',
        isActive: true,
        isLine: false
      },
      methods: {
        btnClick: function() {
          this.isActive = !this.isActive;
        },
        getClasses: function() {
          return {
            active: this.isActive,
            line: this.isLine
          };
        }
      }
    })
  </script>
  <style>
    [v-cloak] {
      display: none;
    }
    
    .active {
      color: red;
    }
    
    .title {
      font-size: 20px;
    }
  </style>
</body>

</html>